home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog 125
/
Freelog_MarsAvril2015_No125.iso
/
Musique
/
Quod Libet
/
quodlibet-3.3.0-installer.exe
/
bin
/
quodlibet
/
cli.pyc
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2014-12-31
|
8KB
|
264 lines
# Source Generated with Decompyle++
# File: in.pyc (Python 2.7)
import os
import sys
from quodlibet.util.dprint import print_, print_e
from quodlibet.remote import Remote, RemoteError
def exit_(status = None, notify_startup = False):
'''Call this to abort the startup before any mainloop starts.
notify_startup needs to be true if QL could potentially have been
called from the desktop file.
'''
if notify_startup:
Gdk = Gdk
import gi.repository
Gdk.notify_startup_complete()
raise SystemExit(status)
def is_running():
'''If maybe is another instance running'''
return Remote.remote_exists()
def control(command, arg = None, ignore_error = False):
'''Sends command to the existing instance if possible and exits.
Will print any response it gets to stdout.
Does not return except if ignore_error is True and sending
the command failed.
'''
if not is_running():
if ignore_error:
return None
None(_('Quod Libet is not running.'), notify_startup = True)
return None
message = None
if arg is not None:
message += ' ' + arg
try:
response = Remote.send_message(message)
except RemoteError:
e = None
if ignore_error:
return None
None(str(e), notify_startup = True)
if response is not None:
print_(response, end = '')
exit_(notify_startup = True)
def process_arguments():
URI = URI
import quodlibet.util.uri
util = util
import quodlibet
const = const
import quodlibet
actions = []
controls = [
'next',
'previous',
'play',
'pause',
'play-pause',
'stop',
'hide-window',
'show-window',
'toggle-window',
'focus',
'quit',
'unfilter',
'refresh',
'force-previous']
controls_opt = [
'seek',
'order',
'repeat',
'query',
'volume',
'filter',
'set-rating',
'set-browser',
'open-browser',
'random',
'song-list',
'queue']
options = util.OptionParser('Quod Libet', const.VERSION, _('a music library and player'), _('[option]'))
options.add('print-playing', help = _('Print the playing song and exit'))
options.add('start-playing', help = _('Begin playing immediately'))
for opt, help in [
('next', _('Jump to next song')),
('previous', _('Jump to previous song or restart if near the beginning')),
('force-previous', _('Jump to previous song')),
('play', _('Start playback')),
('pause', _('Pause playback')),
('play-pause', _('Toggle play/pause mode')),
('stop', _('Stop playback')),
('volume-up', _('Turn up volume')),
('volume-down', _('Turn down volume')),
('status', _('Print player status')),
('hide-window', _('Hide main window')),
('show-window', _('Show main window')),
('toggle-window', _('Toggle main window visibility')),
('focus', _('Focus the running player')),
('unfilter', _('Remove active browser filters')),
('refresh', _('Refresh and rescan library')),
('list-browsers', _('List available browsers')),
('print-playlist', _('Print the current playlist')),
('print-queue', _('Print the contents of the queue')),
('no-plugins', _('Start without plugins')),
('quit', _('Exit Quod Libet'))]:
options.add(opt, help = help)
for opt, help, arg in [
('seek', _('Seek within the playing song'), _('[+|-][HH:]MM:SS')),
('order', _('Set or toggle the playback order'), '[order]|toggle'),
('repeat', _('Turn repeat off, on, or toggle it'), '0|1|t'),
('volume', _('Set the volume'), '(+|-|)0..100'),
('query', _('Search your audio library'), _('query')),
('play-file', _('Play a file'), Q_('command|filename')),
('set-rating', _('Rate the playing song'), '0.0..1.0'),
('set-browser', _('Set the current browser'), 'BrowserName'),
('open-browser', _('Open a new browser'), 'BrowserName'),
('queue', _('Show or hide the queue'), 'on|off|t'),
('song-list', _('Show or hide the main song list'), 'on|off|t'),
('random', _('Filter on a random value'), Q_('command|tag')),
('filter', _('Filter on a tag value'), _('tag=value')),
('enqueue', _('Enqueue a file or query'), '%s|%s' % (Q_('command|filename'), _('query'))),
('enqueue-files', _('Enqueue comma-separated files'), '%s[,%s..]' % (_('filename'), _('filename'))),
('print-query', _('Print filenames of results of query to stdout'), _('query')),
('unqueue', _('Unqueue a file or query'), '%s|%s' % (Q_('command|filename'), _('query')))]:
options.add(opt, help = help, arg = arg)
options.add('sm-config-prefix', arg = 'dummy')
options.add('sm-client-id', arg = 'prefix')
options.add('screen', arg = 'dummy')
def is_vol(str):
if str[0] in '+-':
if len(str) == 1:
return True
str = None[1:]
return str.isdigit()
def is_time(str):
if str[0] not in '+-0123456789':
return False
if None[0] in '+-':
str = str[1:]
parts = str.split(':')
if len(parts) > 3:
return False
return None not in [ p.isdigit() for p in parts ]
def is_float(str):
try:
float(str)
except ValueError:
return False
return True
validators = {
'order': [
'0',
'1',
't',
'toggle',
'inorder',
'shuffle',
'weighted',
'onesong'].__contains__,
'repeat': [
'0',
'1',
't',
'on',
'off',
'toggle'].__contains__,
'volume': is_vol,
'seek': is_time,
'set-rating': is_float }
(opts, args) = options.parse()
for command, arg in opts.items():
if command in controls:
control(command)
continue
if command in controls_opt:
if command in validators and not validators[command](arg):
print_e(_("Invalid argument for '%s'.") % command)
print_e(_('Try %s --help.') % sys.argv[0])
exit_(True, notify_startup = True)
else:
control(command, arg)
if command == 'status':
control('status')
continue
if command == 'print-playlist':
control('dump-playlist')
continue
if command == 'print-queue':
control('dump-queue')
continue
if command == 'list-browsers':
control('dump-browsers')
continue
if command == 'volume-up':
control('volume +')
continue
if command == 'volume-down':
control('volume -')
continue
if command == 'enqueue' or command == 'unqueue':
try:
filename = URI(arg).filename
except ValueError:
filename = arg
control(command, filename)
continue
if command == 'enqueue-files':
control(command, arg)
continue
if command == 'play-file':
try:
filename = URI(arg).filename
except ValueError:
filename = os.path.abspath(util.path.expanduser(arg))
if os.path.isdir(filename):
control('add-directory', filename)
else:
control('add-file', filename)
if command == 'print-playing':
try:
control('print-playing', args[0])
except IndexError:
control('print-playing')
if command == 'print-query':
control(command, arg)
continue
if command == 'start-playing':
actions.append(command)
continue
if command == 'no-plugins':
actions.append(command)
continue
return actions